package com.chen.recruit.domain.model;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

/**
 * 分页查询
 *
 * @author cgy
 * @date 2022-08-20
 */
@Data
public class PageQuery {

    /**
     * 当前页
     */
    private Integer currentPage;

    /**
     * 页大小
     */
    private Integer pageSize;

    /**
     * 当前记录起始索引 默认值
     */
    public static final int DEFAULT_PAGE_NUM = 1;

    /**
     * 每页显示记录数 默认值
     */
    public static final int DEFAULT_PAGE_SIZE = 10;

    /**
     * 构造分页对象
     */
    public <T> Page<T> build() {
        Integer currentPage = ObjectUtil.defaultIfNull(getCurrentPage(), DEFAULT_PAGE_NUM);
        Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE);
        if (pageSize <= 0) {
            pageSize = DEFAULT_PAGE_NUM;
        }
        return new Page<>(currentPage, pageSize);
    }

}
